package com.foodost.cwpstrokes;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class LockImageView extends ImageView {
    
    protected boolean isOpen;
    protected int level;
    
    public LockImageView(Context context) {
        super(context);
    }
    
    public LockImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }
    
    public LockImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }
    
    public void init(AttributeSet attrs){
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.LockImageView);
        isOpen = a.getBoolean(R.styleable.LockImageView_isOpen, false);
        level = a.getInt(R.styleable.LockImageView_level, 1);
        a.recycle();
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(!isOpen){
            Paint paint = new Paint();
            //画到View上  
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.levellock);
            canvas.drawBitmap(bitmap, 0, 0, paint);  
        }
    }

    public boolean isOpen() {
        return isOpen;
    }

    public void setOpen(boolean isOpen) {
        this.isOpen = isOpen;
        invalidate();
    }

    public int getLevel() {
        return level;
    }
    
    
    
    
    
    
    

}
